#include <bits/stdc++.h>
using namespace std;
int T,n,m,L,V;
int d[100010],v[100010],a[100010],p[100010];
int main()
{
    freopen("detect","r",stdin);
    freopen("detect","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>n>>m>>L>>V;
        for(int j=1;j<=n;j++){
            cin>>d[j]>>v[j]>>a[j];
        }
        for(int j=1;j<=n;j++){
            cin>>p[i];
        }
        int sum=0;
        for(int j=1;j<=n;j++){
            if(a[j]==0){
                if(v[j]>V){
                    sum++;
                }
            }
        }
        cout<<sum<<" "<<m-1;
    }


    fclose(stdin);
    fclose(stdout);

    return 0;
}
